import pymysql

# 创建连接对象
conn = pymysql.connect(
    host="192.168.5.116",
    port=3306,
    user="root",
    password="mysql",
    database="python",
    charset="utf8",
)

# 获取游标对象
cursor = conn.cursor()

# 修改 SQL 语句
# sql = "update classes set name='py45' where id=3"
# 添加SQL语句
# sql="insert into classes (name) values('py55'),('py66')"
# 删除SQL语句
sql = "insert into mytext (name) values(%s);"
# 执行 SQL 语句 返回值就是 SQL 语句在执行过程中影响的行数
try:
    for i in range(10000):
        row_count = cursor.execute(sql, "hahah-" + str(i))
        print("SQL 语句执行影响的行数%d" % row_count)
    conn.commit()
except Exception as e:
    print("报错了吗....", e)
    conn.rollback()
finally:
    # 关闭游标
    cursor.close()

    # 关闭连接
    conn.close()
